package com.geovis.emergency.spd.controller.pc;

import com.geovis.common.auth.util.AuthUtil;
import com.geovis.common.core.api.Result;
import com.geovis.common.core.controller.BaseController;
import com.geovis.emergency.spd.biz.pc.service.IPcRollCallPersonService;
import com.geovis.emergency.spd.biz.pc.service.IPcRollCallService;
import com.geovis.emergency.spd.entity.mobile.pojo.dto.RollCallDTO;
import com.geovis.emergency.spd.util.MsgUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 应急预案指挥模块-点名相关接口
 * </p>
 *
 * @author Lonsho
 * @version 1.0
 * @date 2022/6/28
 */
@RestController
@RequestMapping("/pc/pcRollCall")
@RequiredArgsConstructor
@Api(value = "应急预案指挥模块-点名相关接口", tags = "应急预案指挥模块-点名相关接口")
@Slf4j
public class  PcRollCallController extends BaseController<IPcRollCallService> {

    private final IPcRollCallPersonService rollCallPersonService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "发起点名", notes = "发起点名")
    @PostMapping("startRollCall/{pcDrillId}")
    public Result<Void> startRollCall(@PathVariable String pcDrillId){
        baseService.startPcRollCall(pcDrillId);
        return Result.ok();
    }
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "结束点名", notes = "结束点名")
    @PostMapping("stopRollCall/{rollCallId}")
    public Result<Void> stopRollCall(@PathVariable String rollCallId,@RequestParam(value = "msg", required = false) String msg){
        baseService.stopPcRollCall(rollCallId,msg);
        return Result.ok();
    }
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "点名报告", notes = "点名报告")
    @PostMapping("checkIn/{pcRollCallId}")
    public Result<Void> checkIn(@PathVariable String pcRollCallId){
        String userId = AuthUtil.getCurrentUserId();
        rollCallPersonService.updateSign(pcRollCallId, userId);
        //消息通知PC端
        MsgUtil.sendRollCallFeedback(pcRollCallId, userId);
        return Result.ok();
    }
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "获取还未点名的列表",notes = "传演练id")
    @GetMapping("notCheckList/{pcDrillId}")
    public Result<RollCallDTO> notCheckList(@PathVariable String pcDrillId){
        return Result.ok(rollCallPersonService.notCheckList(pcDrillId));
    }
}
